﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace SpaceMan.Menus.Items
{
    class C_CloseButton : I_Item
    {
        C_Drawing drawing;
        Action<string> command;
        MouseState MState, LMState;
        public C_CloseButton(Vector2 position, Action<string> command)
        {
            drawing = S_Global.getDraw("Menus//CloseButton");
            rectangle = new Rectangle((int)position.X, (int)position.Y, 32, 32);
            this.command = command;
            
        }

        public override void Update(bool isActive, Vector2 Position)
        {
            base.Position = Position;
            MState = Mouse.GetState();
            if (isActive)
            {
                Rectangle mouserect = new Rectangle(MState.X, MState.Y, 1, 1);
                if (rectangle.Intersects(mouserect))
                {
                    if (MState.LeftButton == ButtonState.Pressed && LMState.LeftButton == ButtonState.Released)
                        command("close");
                    drawing.Update(Position, 0f, null, null, false, new Color(120, 180, 255));


                }
                else
                {
                    drawing.Update(Position, 0f, null, null, false, new Color(70, 130, 255));
                }
                
            }
            else
            {
                drawing.Update(Position, 0f, null, null, false, new Color(128, 128, 128));
            }
            LMState = MState;
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, DrawMode drawMode, Microsoft.Xna.Framework.Rectangle drawSpace)
        {
            drawing.Draw(spriteBatch, drawMode, drawSpace);
        }
    }
}
